/*
 * End.cpp
 * This file is part of FunBall 
 *
 * Copyright (C) 2012 - Francois Berder
 *
 * FunBall is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * FunBall is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 

#include "End.hpp"
#include "Platform.hpp"
#include "Ball.hpp"


End::End(const sf::Vector2f pos):
Entity(),
m_isOver(false),
m_obj(),
m_shape(sf::Vector2f(50,50))
{
    m_shape.setOutlineThickness(2.f);
    m_shape.setOutlineColor(sf::Color::Blue);
    m_shape.setOrigin(25.f,25.f);
    m_shape.setPosition(pos);
    
    json::Object o;
    o["type"] = json::String("static");
    o["angle"] = json::Number(0);
    o["position"]["x"] = json::Number(pos.x);
    o["position"]["y"] = json::Number(-pos.y);
    o["fixedRotation"] = json::Boolean(false);
    o["bullet"] = json::Boolean(false);
    o["shapeType"] = json::String("square");
    o["side"] = json::Number(50.f);
    
    m_obj.load(o);
    m_obj.body()->SetUserData(this);
}

void End::collideWith(Entity& e)
{
    e.collideWith(*this);
}
void End::collideWith(Ball& b)
{
    m_isOver = true;
}

void End::collideWith(Platform& p)
{
}
void End::collideWith(End& e)
{
}

void End::endCollideWith(Entity& e)
{
    e.endCollideWith(*this);
}

void End::endCollideWith(Ball& b)
{
}

void End::endCollideWith(Platform& p)
{
}

void End::endCollideWith(End& e)
{
}


void End::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
    target.draw(m_shape,states);
}

bool End::isOver() const
{
    return m_isOver;
}


